class Solution {
public:
    vector<int> canSeePersonsCount(vector<int>& heights) {
        int n = heights.size();
        vector<int> ans(n,0);
        vector<int> s1;
        for(int i = 0;i<n;++i)
        {
            while(!s1.empty() && heights[s1.back()] < heights[i])
            {
                ans[s1.back()]++;
                s1.pop_back();
            }
            if(!s1.empty())
            {
                ans[s1.back()]++;
            }
            s1.push_back(i);
        }
        return ans;
    }
};